package com.wanmait.happyheating.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.happyheating.pojo.FaultType;
import com.wanmait.happyheating.mapper.FaultTypeMapper;
import com.wanmait.happyheating.service.FaultTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 故障分类表 服务实现类
 * </p>
 *
 * @author yuQianTao
 * @since 2021-05-13
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class FaultTypeServiceImpl extends ServiceImpl<FaultTypeMapper, FaultType> implements FaultTypeService {
    @Resource
    private FaultTypeMapper faultTypeMapper;
    @Override
    public PageInfo<FaultType> findFaultTypeByPage(Integer pageNum,Integer pageSize) {
        //暂时每页显示条数为3 后期通过数据库读取
        PageHelper.startPage(pageNum,pageSize);
        List<FaultType> faultTypeList=faultTypeMapper.selectList(null);
        //暂时导航页码数为5
        PageInfo<FaultType> faultTypePageInfo=new PageInfo<>(faultTypeList,5);
        return faultTypePageInfo;
    }

    //模糊查询

    @Override
    public PageInfo<FaultType> likeFaultTypeByPage(Integer pageNum,Integer pageSize,String title) {
        //暂时每页显示条数为3 后期通过数据库读取
        LambdaQueryWrapper<FaultType> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.like(FaultType::getTitle,title);
        PageHelper.startPage(pageNum,pageSize);
        List<FaultType> faultTypeList=faultTypeMapper.selectList(queryWrapper);
        //暂时导航页码数为5
        PageInfo<FaultType> faultTypePageInfo=new PageInfo<>(faultTypeList,5);
        return faultTypePageInfo;
    }
}
